package com.netty.pro.netty.heartbeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * @author xuzn
 * @ClassName: MyServerHandler
 * @ProjectName netty-pro
 * @date 2020/3/16/17:57
 */
public class MyServerHandler extends SimpleChannelInboundHandler {
  @Override
  protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {

  }

  @Override
  public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
      IdleStateEvent event = (IdleStateEvent) evt;
      String eventType = null;
      switch (event.state()) {
        case READER_IDLE:
          eventType = "读空闲";
          break;
        case WRITER_IDLE:
          eventType = "写空闲";
          break;
        case ALL_IDLE:
          eventType = "读写空闲";
          break;
      }
      System.out.println(eventType);
      System.out.println("空闲之后写入自己的逻辑");
    }
  }
}
